package car.aistar.service.impl;

import car.aistar.dao.CarDetailDao;
import car.aistar.dto.BrandAndPrice;
import car.aistar.entity.CarDetail;
import car.aistar.service.CarDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * (CarDetail)表服务实现类
 *
 * @author makejava
 * @since 2020-10-02 19:05:03
 */
@Service("carDetailService")
public class CarDetailServiceImpl implements CarDetailService {
    @Autowired
    private CarDetailDao carDetailDao;


    /**
     *@Author 许华钢
     *@Description 管理员页面车辆管理分页实现类
     *@Date 7:29 2020/10/8
     *@Param [pageNow, pageSize]
     *@return com.github.pagehelper.PageInfo<car.aistar.entity.CarDetail>
     **/
    @Override
    public List<CarDetail> findAllCarDetail(String search) {
        return carDetailDao.findAllCarDetail(search);
    }

    /**
     *@Author 许华钢
     *@Description 管理员页面车辆管理分页实现类
     *@Date 7:32 2020/10/8
     *@Param [pageNow, pageSize]
     *@return com.github.pagehelper.PageInfo<car.aistar.entity.CarDetail>
     **/
    @Override
    public PageInfo<CarDetail> findByPageCarDetail(String search, Integer pageNow, Integer pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<CarDetail> carDetailList = carDetailDao.findAllCarDetail(search);
        PageInfo<CarDetail> petPageInfo = new PageInfo<>(carDetailList);
        return petPageInfo;
    }

    /**
*@Author 肖相荣
*@Description //TODO 销售人员的负责车辆分页实现类
*@Date 15:06 2020/10/4
*@Param [pageNow, pageSize]
*@return com.github.pagehelper.PageInfo<car.aistar.entity.CarDetail>
**/
    @Override
    public PageInfo<CarDetail> findByPage (Long id,Integer pageNow, Integer pageSize){
        PageHelper.startPage(pageNow,pageSize);
        List<CarDetail> carDetailList = carDetailDao.findAll(id);
        PageInfo<CarDetail> petPageInfo = new PageInfo<>(carDetailList);
        return petPageInfo;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CarDetail queryById(Long id) {
        return this.carDetailDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CarDetail> queryAllByLimit(int offset, int limit) {
        return this.carDetailDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param carDetail 实例对象
     * @return 实例对象
     */
    @Override
    public CarDetail insert(CarDetail carDetail) {
        this.carDetailDao.insert(carDetail);
        return carDetail;
    }

    /**
     * 修改数据
     *
     * @param carDetail 实例对象
     * @return 实例对象
     */
    @Override
    public CarDetail update(CarDetail carDetail) {
        this.carDetailDao.update(carDetail);
        return this.queryById(carDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.carDetailDao.deleteById(id) > 0;
    }

    @Override
    public List<CarDetail> queryAll(CarDetail carDetail) {
        return this.carDetailDao.queryAll(carDetail);
    }

    @Override
    public List<String> findCgear() {
        return this.carDetailDao.findCgear();
    }

    @Override
    public List<String> findCpaifang() {
        return this.carDetailDao.findCpaifang();
    }

    @Override
    public List<String> findCcus() {
        return this.carDetailDao.findCcus();
    }

    @Override
    public List<Integer> findCmileage() {
        return this.carDetailDao.findCmileage();
    }

    @Override
    public List<Integer> findCseat() {
        return this.carDetailDao.findCseat();
    }

    @Override
    public List<Integer> findAge() {
        return this.carDetailDao.findAge();
    }

}